﻿Imports DTO

Public Class DAOrganization

    Inherits DataProvider

    ''' <summary>
    ''' Config server name
    ''' </summary>
    ''' <param name="serverName"></param>
    ''' <remarks></remarks>
    Shared Sub ConfigServerName(ByVal serverName As String)

        ' call constructor base class
        ConfigServer(serverName)

    End Sub


    ''' <summary>
    ''' Get all organiztion.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetOrganization() As DataTable

        Return Query("GetOrganization")

    End Function

    ''' <summary>
    ''' Insert new organization
    ''' </summary>
    ''' <param name="dtoOrganization"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function AddOrganization(ByVal dtoOrganization As DTOOrganization) As Integer

        ' param name
        Dim params As String() = New String() {"@no", "@name", "@supNo", "level", "groupNo", "@address", "@note"}

        Dim supNo As Object
        If String.IsNullOrEmpty(dtoOrganization.SupProperty) Then

            supNo = DBNull.Value

        Else

            supNo = dtoOrganization.SupProperty

        End If

        Dim group As Object
        If String.IsNullOrEmpty(dtoOrganization.GroupProperty) Then

            group = DBNull.Value

        Else

            group = dtoOrganization.GroupProperty

        End If

        Dim address As Object
        If String.IsNullOrEmpty(dtoOrganization.AddressProperty) Then

            address = DBNull.Value

        Else

            address = dtoOrganization.AddressProperty

        End If

        Dim note As Object
        If String.IsNullOrEmpty(dtoOrganization.NoteProperty) Then

            note = DBNull.Value

        Else

            note = dtoOrganization.NoteProperty

        End If

        ' param value
        Dim values As Object() = New Object() {dtoOrganization.NoProperty, dtoOrganization.NameProperty, supNo, dtoOrganization.LevelProperty, group, address, note}

        Return Update("AddOrganization", params, values)

    End Function

    ''' <summary>
    ''' Update organization
    ''' </summary>
    ''' <param name="dtoOrganization"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function UpdateOrganization(ByVal dtoOrganization As DTOOrganization) As Integer

        Dim params As String() = New String() {"@no", "@name", "@supNo", "@level", "@groupNo", "@address", "@note"}

        Dim supNo As Object
        If String.IsNullOrEmpty(dtoOrganization.SupProperty) Then

            supNo = DBNull.Value

        Else

            supNo = dtoOrganization.SupProperty

        End If

        Dim group As Object
        If String.IsNullOrEmpty(dtoOrganization.GroupProperty) Then

            group = DBNull.Value

        Else

            group = dtoOrganization.GroupProperty

        End If

        Dim address As Object
        If String.IsNullOrEmpty(dtoOrganization.AddressProperty) Then

            address = DBNull.Value

        Else

            address = dtoOrganization.AddressProperty

        End If

        Dim note As Object
        If String.IsNullOrEmpty(dtoOrganization.NoteProperty) Then

            note = DBNull.Value

        Else

            note = dtoOrganization.NoteProperty

        End If

        ' param value
        Dim values As Object() = New Object() {dtoOrganization.NoProperty, dtoOrganization.NameProperty, supNo, dtoOrganization.LevelProperty, group, address, note}

        Return Update("UpdateOrganization", params, values)

    End Function

    ''' <summary>
    ''' delete organization
    ''' </summary>
    ''' <param name="dtoOrganization"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function DeleteOrganization(ByVal dtoOrganization As DTOOrganization) As Integer

        Return Update("DeleteOrganization", New String() {"@no"}, New Object() {dtoOrganization.NoProperty})

    End Function


    ''' <summary>
    '''  Get Organizations are company.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetCompany() As DataTable

        Return Query("GetCompany")

    End Function

    ''' <summary>
    ''' check organization still contain employee
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function CheckOrganContainEmployee(ByVal organNo As String) As Integer

        Return NonQueryReturn("CheckOrganContainEmployee", New String() {"@organNo"}, New Object() {organNo})

    End Function


End Class
